    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package progweb.project.Manager;

import java.io.PrintWriter;
import org.apache.log4j.*;

/**
 *
 * @author Davide Bonomelli, Valentino Briani
 */
public class GUIManager {
    private static org.apache.log4j.Logger log=Logger.getLogger(GUIManager.class);
    private PrintWriter out;
    
    
    public GUIManager(PrintWriter newOut){
        this.out=newOut;
    }
    public PrintWriter getWriter(){
        return this.out;
    }
    @Override
    public void finalize(){
        try {
            this.out.close();
            super.finalize();
            log.debug("Chiusura out");
        } catch (Throwable ex) {
            log.error("", ex);
        }
    }
    public void printHeader(){
        
    }
    
    public void printContent(){
        
    }
    
    public void printFooter(){
        
    }
    
    public void printErrorPage(String message,String backPage){
        this.out.println("<!DOCTYPE html>\n<html>\n\t<head>\n\t\t"
                + "<title>I Provetta di Programmazione per il Web</title>\n\t\t"
                + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />"
                + "\n\t\t<meta name=\"Keywords\" content=\"\" />"
                + "\n\t\t<meta name=\"Description\" content=\"\" />"
                + "\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" />"
                + "\n\t</head>\n\t<body style=\"text-align=center; background: none;\">"
                + "\n\t\t<div id=\"error\">\n\t\t\t<div id=\"content\">"
                + "\n\t\t\t\t<h2>Si è verificato un errore!</h2>"
                + "\n\t\t\t\t<p><b>Messaggio:</b> "+message+"</p>"
                + "\n\t\t\t\t<div id=\"back\"><a href=\""+backPage+"\">Indietro</a></div>"
                + "\n\t\t\t</div>"
                +"\n\t\t</div>\n\t</body>\n</html>");
    }
    
    public void printPageWithContent(String newContent,String menu){
        this.out.println("<!DOCTYPE html>\n<html>\n\t<head>\n\t\t"
                + "<title>I Provetta di Programmazione per il Web</title>\n\t\t"
                + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />"
                + "\n\t\t<meta name=\"Keywords\" content=\"\" />"
                + "\n\t\t<meta name=\"Description\" content=\"\" />"
                + "\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" />"
                + "\n\t</head>\n\t<body>"
                + "\n\t\t<div id=\"container\">\n\t\t\t<div id=\"left\">\n\t\t\t\t"+menu+"\n\t\t\t</div>"
                + "\n\t\t\t<div id=\"right\">"
                + "\n\t\t\t\t"+newContent
                + "\n\t\t\t</div>\n\t\t</div>\n\t</body>\n</html>");
    }
    
    public void printPage(String titolo, String menu, Medico medico, String ultimo_accesso, String contenuto) {
        this.out.println(
                    "<html>\n"
                    + "<head>\n"
                    + "<title>I Provetta di Programmazione per il Web</title>\n"
                    + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n"
                    + "<meta name=\"Keywords\" content=\"\" />\n"
                    + "<meta name=\"Description\" content=\"\" />\n"
                    + "\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" />"
                    + "</head>\n"
                    + "<body>\n"
                    + "<div id=\"container\">\n"
                    + "<h4>> Welcome Medico " + titolo + "</h4>\n"
                    + "<div id=\"left\">\n"
                    + menu
                    + "</div>\n"
                    + "<div id=\"right\">\n"
                    + "<div id=\"myData\">\n"
                    + "<h4>Nome:</h4><p>" + medico.getNome() + "</p>\n"
                    + "<h4>Cognome:</h4><p>" + medico.getCognome() + "</p>\n"
                    + "<h4>Ultimo accesso:</h4><p>" + ultimo_accesso + "</p>\n"
                    + "</div>\n"
                    + contenuto
                    + "</div>\n"
                    + "</div>\n"
                    + "</body>\n"
                    + "</html>"
                    );
    }
    
    public void printPage(PrintWriter out, String titolo, String menu, Medico medico, String ultimo_accesso, String contenuto) {
        try {
            log.debug("Stampa pagina");
            out.println(
                    "<html>\n"
                    + "<head>\n"
                    + "<title>I Provetta di Programmazione per il Web</title>\n"
                    + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />\n"
                    + "<meta name=\"Keywords\" content=\"\" />\n"
                    + "<meta name=\"Description\" content=\"\" />\n"
                    + "\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" />"
                    + "</head>\n"
                    + "<body>\n"
                    + "<div id=\"container\">\n"
                    + "<h4>> Welcome Medico " + titolo + "</h4>\n"
                    + "<div id=\"left\">\n"
                    + menu
                    + "</div>\n"
                    + "<div id=\"right\">\n"
                    + "<div id=\"myData\">\n"
                    + "<h4>Nome:</h4><p>" + medico.getNome() + "</p>\n"
                    + "<h4>Cognome:</h4><p>" + medico.getCognome() + "</p>\n"
                    + "<h4>Ultimo accesso:</h4><p>" + ultimo_accesso + "</p>\n"
                    + "</div>\n"
                    + contenuto
                    + "</div>\n"
                    + "</div>\n"
                    + "</body>\n"
                    + "</html>"
                    );
        } finally {
            out.close();
            log.debug("Pagina stampata correttamente");
        }
    }
    
    /**
     * metodo che stampa a video la pagina di registrazione effettuata
     * @param message il messaggio da stampare nel box
     * @param backPage pagina a cui il bottone Indietro punta
     */
    
    public void printRegistrationPage(String message,String backPage){
        try {
            this.out.println("<!DOCTYPE html>\n<html>\n\t<head>\n\t\t"
                    + "<title>I Provetta di Programmazione per il Web</title>\n\t\t"
                    + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\" />"
                    + "\n\t\t<meta name=\"Keywords\" content=\"\" />"
                    + "\n\t\t<meta name=\"Description\" content=\"\" />"
                    + "\n\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\" />"
                    + "\n\t</head>\n\t<body style=\"text-align=center; background: none;\">"
                    + "\n\t\t<div id=\"error\">\n\t\t\t<div id=\"content\">"
                    + "\n\t\t\t\t<h2>Benvenuto!</h2>"
                    + "\n\t\t\t\t<p><b>Registrazione:</b> "+message+"</p>"
                    + "\n\t\t\t\t<div id=\"back\"><a href=\""+backPage+"\">Indietro</a></div>"
                    + "\n\t\t\t</div>"
                    +"\n\t\t</div>\n\t</body>\n</html>");
        } finally {
            this.out.close();
        }
    }
}
